const menu = [
  {
    name: '登录',
    path: 'login',
    component: () => require('../routes/Login/LoginPage'),
    model: () => require('../models/Account')
  },
  {
    name: '主页',
    component: () => require('../routes/Index/IndexPage')
  },
]

const formatter = (menu, parent, authority) => {
  let res = {}

  menu && menu.forEach(v => {
    // 处理合并路径
    const paths = `${parent ? `/${parent}` : ''}/${v.path || ''}`
    const item = Object.assign({}, v, {
      paths,
    })

    res[paths] = authority ? Object.assign(item, {
      authority: authority
    }) : item

    if (v.children && v.children.length > 0)  {
      Object.assign(res, formatter(v.children, v.path, v.authority))
    }
  })

  return res
}

export default formatter(menu)
